package com.vcms.view.simulation.customer;

import java.awt.Container;
import java.awt.Panel;
import java.awt.event.ActionEvent;

import com.vcms.controller.customer.TransactionController;

@SuppressWarnings("serial")
public abstract class DrinkSelectionBox extends Panel {

	protected int[] drinkId;
	protected TransactionController transactionController;
	protected DrinkSelection[] drinkSelection;

	public DrinkSelectionBox(Container composite, TransactionController tCtrl) {
		this.transactionController = tCtrl;
	}

	protected void initDrinkSelection() {
		initUI();
		setAction();
	}
	
	protected abstract void initUI();
	
	protected abstract void setAction();
	
	public void update(int brandIndex, int quantity, int price, String name) {
		drinkSelection[brandIndex].setName(name);
		drinkSelection[brandIndex].setPrice(price);
		drinkSelection[brandIndex].setQuantity(quantity);
		drinkSelection[brandIndex].setItemState(quantity == 0 ? false : true);
	}
	
	public void setActive(boolean active) {
		if (active) {
			for (int i : drinkId) {
				drinkSelection[i].setItemActive(drinkSelection[i].getItemState());
			}
		} else {
			for(int i : drinkId){
				drinkSelection[i].setItemActive(false);
			}
		}
	}
	
	public abstract void doActionPerformed(ActionEvent e);

	/* private class for drink selection */
	protected abstract static class DrinkSelection extends Panel {
		
		protected int brandIndex;
		protected int quantity;
		protected int price;
		protected String name;
		protected boolean state;

		public void setItemState(boolean active) {
			this.state = active;
		}
		
		public boolean getItemState() {
			return this.state;
		}

		public void setName(String name) {
			this.name = name;
		}
		
		public void setPrice(int price) {
			this.price = price;
		}
		
		public void setQuantity(int quantity)
		{
			this.quantity = quantity; 
		}
		
		public abstract void setItemActive(boolean active);

	}

}
